package com.gxuwz.attend.web.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

/**
 * 字符编码过滤器
 */
@WebFilter(filterName = "CharacterEncodingFilter",urlPatterns = {"/*"})
public class CharacterEncodingFilter implements Filter {
    private final static String ENCODE="UTF-8";
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //请求字符编码默认为utf-8
        servletRequest.setCharacterEncoding(ENCODE);
        servletResponse.setCharacterEncoding(ENCODE);
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
